﻿
@{
    ViewBag.Title = "Index";
}

@{
    ViewBag.Title = "驾驶证列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        行驶证列表
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">行驶证列表</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <form id="search-form" class="form-inline">
                        <div class="form-group">
                            <label>号牌号码</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="11" name="PlateNo" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>VIN车架号</label>
                            <input type="text" class="form-control" style="width:100px;" name="VIN" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>发动机号</label>
                            <input type="text" class="form-control" style="width:100px;" name="EngineNo" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>姓名</label>
                            <input type="text" class="form-control" style="width:100px;" name="Name" autocomplete="off" />
                        </div>
                        @*<div class="form-group">
            <label>车辆名称</label>
            <input type="text" class="form-control" style="width:100px;" name="CarName" autocomplete="off" />
        </div>*@
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnSearch">查找</button>
                        </div>
                        <h3 class="box-title"></h3>
                    </form>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding" id="parData">
                </div>
                <div class="box-footer clearfix ">
                    <ul id="pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>
    <!-- 审批模态框（Modal） -->
    <div class="modal fade" id="vehicleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">行驶证信息</h4>
                </div>
                <div class="modal-body" id="modal_VehicleInfo">正在加载中。。。</div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" id="model_btn_yes">通过</button>
                    <button type="button" class="btn btn-primary" id="model_btn_no">驳回</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</section>
@section scriptsBottom{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnSearch").click(function () {
                pageIndex = 1;
                list();
            });
            list();
            $("#model_btn_yes").click(function () {
                updateVehiclStatus(2);
            });
            $("#model_btn_no").click(function () {
                updateVehiclStatus(3);
            });
        });
        var currentVehicleId = "";
        function approval(id) {
             currentVehicleId = id;
             var url = '@Url.Action("ModalVehicleDetail", "VehicleLicense")' + "?id=" + id;
             $("#modal_VehicleInfo").load(url);
             $("#vehicleModal").modal('show');
        }
        //页码
        var pageIndex = 1;
        //查询
        function list() {
            var fdata = $("#search-form").serializeJson();
            var url = '@Url.Action("ParList", "VehicleLicense")' + "?page=" + pageIndex;
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'POST',
                data: fdata,
                dataType: "html",
                success: function (data) {
                    document.getElementById('parData').innerHTML = data;
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: document.getElementById('total').value,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            list();
                        }
                    });
                }
            });
        }
        function updateVehiclStatus(status) {
            var url = '@Url.Action("UpdateUserVehicleStatus", "VehicleLicense")';
            var data = {
                "VehicleLicenseID": currentVehicleId,
                "VehicleStatus": status
            };
            BMCW.ajax({
                url: url,
                type: "POST",
                data: data,
                success: function (res) {
                    if (res.status == 0) {
                        BMCW.alert("审批提交成功");
                        pageIndex = 1;
                        list();
                    } else {
                        BMCW.alert(res.message);
                    }
                    $("#vehicleModal").modal('hide');
                },
                error: function (err) {
                    $("#modal_VehicleInfo").html("正在加载中。。。");
                    $("#vehicleModal").modal('hide');
                }
            });
        }

    function detail(id) {
        window.location.href = "@Url.Action("Detail", "VehicleLicense")" + "?id=" + id;
    }
    </script>
}
